package com.sxj.PDMS.service.impl;

import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxj.PDMS.model.dto.admin.DataInformationRequest;
import com.sxj.PDMS.model.dto.student.StudentPersonalDataRequest;
import com.sxj.PDMS.model.entity.DataInformationList;
import com.sxj.PDMS.model.entity.StudentUploadData;
import com.sxj.PDMS.model.vo.PagingQueryResponse;
import com.sxj.PDMS.service.StudentUploadDataService;
import com.sxj.PDMS.mapper.StudentUploadDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import static com.sxj.PDMS.utils.VerifyUtil.formatDate;

/**
 * @author 503c'j
 * @description 针对表【student_upload_data】的数据库操作Service实现
 * @createDate 2024-06-17 08:38:04
 */
@Service
@Slf4j
public class StudentUploadDataServiceImpl extends ServiceImpl<StudentUploadDataMapper, StudentUploadData>
        implements StudentUploadDataService {
    @Autowired
    private StudentUploadDataMapper studentUploadDataMapper;

    @Override
    public PagingQueryResponse<StudentUploadData> selectAll(Integer page, Integer pageSize) {
        Integer start = (page - 1) * pageSize;
        List<StudentUploadData> studentUploadDataLists = studentUploadDataMapper.selectAll(start, pageSize);
        Long total = studentUploadDataMapper.selectTotal();
        PagingQueryResponse<StudentUploadData> pagingQueryResponse = new PagingQueryResponse<>();

        pagingQueryResponse.setRows(studentUploadDataLists);

        pagingQueryResponse.setTotal(total);

        return pagingQueryResponse;
    }

    @Override
    public PagingQueryResponse<StudentUploadData> studentUploadDataSelect(Integer page, Integer pageSize, Date time, String studentNumber) {
        Integer start = (page - 1) * pageSize;

        List<StudentUploadData> studentUploadDataLists = studentUploadDataMapper.selectByStudentNumber(start, pageSize, time,studentNumber);
        Long total = studentUploadDataMapper.selectTotalByStudentNumber(time,studentNumber);

        PagingQueryResponse<StudentUploadData> pagingQueryResponse = new PagingQueryResponse<>();
        pagingQueryResponse.setRows(studentUploadDataLists);
        pagingQueryResponse.setTotal(total);

        return pagingQueryResponse;
    }

    @Override
    public Boolean personalDataUpload(StudentPersonalDataRequest studentPersonalDataRequest) throws ParseException {

            StudentUploadData studentUploadData = new StudentUploadData();
            studentUploadData.setStudentNumber(studentPersonalDataRequest.getStudentNumber());
            studentUploadData.setDataAddress(studentPersonalDataRequest.getDataAddress());
            // 获取当前时间
            LocalDateTime currentTime = LocalDateTime.now();
            studentUploadData.setTime(formatDate(currentTime));

            boolean saved = this.save(studentUploadData);
            return saved;

    }
}




